using DG.Tweening;
using Entitas;
using UnityEngine;

public class GameItemView : View, IItemIndexListener
{
    public override void Link(IEntity entity, IContext context)
    {
        base.Link(entity, context);
        _gameEntity.AddItemIndexListener(this);
    }

    public void OnItemIndex(GameEntity entity, CustomVector2 index)
    {
        transform.DOMove(new Vector3(index.x, index.y), 0.3f).OnComplete(() => _gameEntity.isMoveComplete = true);
    }

    public override void OnDestroy(GameEntity entity)
    {
        base.OnDestroy(entity);
        float time = 0.2f;
        transform.DOKill();
        transform.DOScale(Vector3.one * 1.3f, time);
        transform.GetComponent<SpriteRenderer>().DOColor(Color.clear, time);
    }
}